home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / D-G / FORTRAN Goodies / PcallsF / PcallsF.p < prev   
Encoding:
Text File  |  1990-12-03  |  2.4 KB  |  83 lines  |  [TEXT/MPS ]

  1. {Sample program showing the different ways Pascal can call 
  2. FORTRAN subroutines and fucntions.}
  3.  
  4. {There are three ways that variables can be passed from 
  5. Pascal to FORTRAN.  Passing by reference is FORTRAN's default
  6. for all types except strings and characters, which are passed 
  7. by descriptor.  Starting with Version 2.0, FORTRAN can also 
  8. accept arguments by value, which is Pascal's default.}
  9.  
  10. {    Example provided for owners of Language Systems FORTRAN
  11.     © 1990 Language Systems Corp.}
  12.  
  13. program PcallsF;
  14. uses
  15.     MemTypes,
  16.     {$U $$SHELL(PInterfaces)FortTypes.p}
  17.     FortTypes;  {Unit that defines FORTRAN Types}
  18.     
  19. type
  20.     ch20 = packed array[1..20] of char; {Same as CHARACTER*20}
  21.     intary = array[1..100] of integer;     {Define an array type}
  22.     COMMON = RECORD
  23.         ia2: intary;
  24.         sum2,i2: integer;
  25.     END;
  26.     
  27. var
  28.     ca        : ch20;        {Variable we want the FORTRAN subroutine to set}
  29.     dca        : DescRec;    {Descriptor to pass to the routine}
  30.     ia        : intary;    {The array}
  31.     sum        : integer;    {Total of adding all the array elements}
  32.     i        : integer;    {Work counter}
  33. {$J+}
  34.     _TEST_    : Common;
  35. {Define the FORTRAN subroutines external}
  36. procedure SumArray(var iary : intary; num: integer;var total : integer);
  37.     External;    {1st argument by reference, 2nd by value}
  38. procedure SumArray2;
  39.     External;    {COMMON}
  40. procedure Charfill(var desc : DescRec);
  41.     External;     {character passed by descriptor}
  42. procedure Charfill2(Var the_char : ch20);
  43.     External;    {character passed by reference}
  44.     
  45. begin
  46.     InitFORTRAN;
  47.     for i:= 1 to 100 do     {Fill the array with numbers}
  48.         ia[i] := i;
  49.         
  50.     SumArray(ia,i-1,sum);    {Call the subroutine}
  51.     
  52.     writeln('The total is: ',sum); {Display the total}
  53.     for i := 1 to 100 do     {Fill the array with numbers}
  54.         _test_.ia2[i] := i;
  55.     _test_.i2 := 100;
  56.     SumArray2;                {Call the subroutine}
  57.     
  58.     writeln('The COMMON total is: ',_test_.sum2);    {Display the total}
  59.     
  60.     with dca do {Set up the descriptor for the character variable}
  61.         begin
  62.             DataPtr := @ca; {Point to the array}
  63.             DataSize := SizeOf(ca);    {Set up the size}
  64.             SymT := chard;    {Let the called routine know what it has}
  65.         end;
  66.         
  67.     Charfill(dca);    {Call the subroutine and pass the descriptor}
  68.     
  69.     writeln('This is what came back from Charfill:');
  70.     {Display what we got}
  71.     for i := 1 to 20 do
  72.         write(ca[i]);
  73.     writeln;
  74.     
  75.     Charfill2(ca);    {Call the subroutine and pass by reference (VAR)}
  76.     
  77.     writeln('This is what came back from Charfill2:');
  78.     {Display what we got}
  79.     for i := 1 to 20 do
  80.         write(ca[i]);
  81.     writeln;
  82. end.
  83.